<?php
class Talstack extends AppModel
{
	var $name='Talstack';
	var $primaryKey = 'id'; 
	var $order='Talstack.tname asc';
	var $conditions = "Talstack.is_deleted='0'";
    function getsubtype($id)
    {
    	$where="";
    	$where.=" Talstack.super_class='$id' ";
    	$where.="and Talstack.is_deleted='0'";
    	$objtype=$this->findAll($where);
    	return $objtype;
    }
    
    function getTname($super_class=null)
    {
    	$options=array();
    	$where="";
    	if($super_class){
    		$where.="super_class ='".$super_class."' ";
    	}else{
    		$where.="super_class is null";
    	}$options['']="请选择类型";
    	if(!empty($_GET['gov']) && $super_class==null){
    		
    		$objt=classregistry::init('Codevalue')->findById($_GET['gov'],"Codevalue.value,Codevalue.id");
    		$objct=classregistry::init('Codetype')->getCValues($objt["Codevalue"]["value"],1);
    		if($objct){
    			$s="'".$objt["Codevalue"]["id"]."'";
    			foreach ($objct as $key=>$t){
    				$s.=",'".$key."'";
    			}
    			$where.=" and gov in ($s)";
    		}else{
    			$where.=" and gov='".$_GET['gov']."'";
    		}
    	}
    	$where.=" and is_deleted='0'";
    	$objtypes= $this->findAll($where,"`Talstack`.`id`, `Talstack`.`tname`, `Talstack`.`super_class`");
    	if(empty($objtypes)){
    		$options=null;
    	}
    	foreach ($objtypes as $objtype){
	 		$options[$objtype['Talstack']['id']]=$objtype['Talstack']['tname'];
		}
		return $options;
    }
    var $tname="";
    var $tid="";
    var $gov="";
    function showtname($super_class)
    {
    	if($super_class){
    		$this->subtame($super_class);
    	}
    }
    function subtame($super_class){
    	$where="id='".$super_class."'";
    		$where.=" and is_deleted='0'";
    	$objtypes= $this->findAll($where,"`Talstack`.`id`, `Talstack`.`tname`, `Talstack`.`super_class`, `Talstack`.`gov`");
    	foreach ($objtypes as $objtype){
    		$id=$objtype['Talstack']['id'];
    		$tname=$objtype['Talstack']['tname'];
    		$super_class=$objtype['Talstack']['super_class'];
    		$gov=$objtype['Talstack']['gov'];
    		//$desc=$objtype['Talstack']['desc'];
    		if($super_class!=""){
    			$this->subtame($super_class);
    		}
    		$this->tname.=$tname.'/';
    		$this->tid.=$id.'/';
    		$this->gov=$gov;
    	}
    }
    function getidlistgov($gov)
    {
    	$objt=classregistry::init('Codevalue')->findById($gov,"Codevalue.value,Codevalue.id");
    	$objct=classregistry::init('Codetype')->getCValues($objt["Codevalue"]["value"],1);
    	$govwhere="";
    	if($objct){
    		$s="'".$objt["Codevalue"]["id"]."'";
    		foreach ($objct as $key=>$t){
    			$s.=",'".$key."'";
    		}
    		$govwhere.="gov in ($s)";
    	}else{
    		$govwhere.=" gov='".$_GET['gov']."'";
    	}
    	$objtypes= $this->findAll("$govwhere and is_deleted='0'","`Talstack`.`id`");
    	$s="'1'";
    	foreach ($objtypes as $objtype){
    		$id=$objtype['Talstack']['id'];
    		$s.=",'".$id."'";
    	}
    	$sql="CompTalent.type_id in(".$s.") and ";
    	return $sql;
    }
    
    var $talstackidlist="";
    function gettalentpname($tname)
    {
    	$where = "tname='".$tname."' and is_deleted='0'";
    	$talstack = $this->findAll($where);
    	$id = $talstack[0]["Talstack"]["id"];
    	$this->talstackidlist.="'".$id."',";
    	$this->subpname($id);
    }
    function subpname($super_class){
    	$stacks = $this->findAll("super_class='$super_class' and is_deleted='0'");
    	foreach($stacks as $stack)
    	{
    		$id = $stack["Talstack"]["id"];
    		$ids = $stack["Talstack"]["tname"];
    		$this->talstackidlist.="'".$id."',";
    		$this->subpname($id);
    	}
    }
 	function getTalstackidlist(){
 		return rtrim($this->talstackidlist,",");	
 	}
}
?>